﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace EasyLibrary.AR.Classes
{
    public class Empresa :ActiveRecord
    {
        public int IDEmpresa { get; set; }
        public string Nome { get; set; }
        public bool Activo { get; set; }
        public DateTime DataInsercao { get; set; }

        public Empresa()
        {
            
        }

        public Empresa(int id,string n)
        {
            this.IDEmpresa = id;
            this.Nome = n;

        }

      protected Empresa(DataRow row)
		{
            this.IDEmpresa = (int)row["IDEmpresa"];
            this.Nome = (string)row["Nome"];
        
		}


      public IList LoadAll()
      {
          try
          {
              DataSet ds = ExecuteQuery(GetConnection(false), "SELECT IDEmpresa, Nome FROM Empresas WHERE Activo = 1 ORDER BY Nome ASC");

              IList ret = new ArrayList();

              foreach (DataRow r in ds.Tables[0].Rows)
              {
                  Empresa emp = new Empresa(r);
                  ret.Add(emp);
              }

              return ret;
          }
          catch (Exception ex)
          {
              throw new ApplicationException("Erro BD", ex);
          }
      }

      public override void Save()
      {
          throw new NotImplementedException();
      }

       

    }
}
